home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 201-225 / disk_222 / plplot / src / source.zoo / plform.c < prev    next >
C/C++ Source or Header  |  1989-05-15  |  1KB  |  38 lines

  1. /* Formats a floating point value in one of the following formats   */
  2. /* (i)  If mode == 0, use floating point format with "precision"    */
  3. /*      places after the decimal point.                             */
  4. /* (ii) If mode == 1, use scientific notation with one place before */
  5. /*      the decimal point and "precision" places after.             */
  6.  
  7. #include "plplot.h"
  8. #include <stdio.h>
  9. #include <string.h>
  10.  
  11. void plform(value,mode,prec,result)
  12. float value;
  13. int mode, prec;
  14. char *result;
  15. {
  16.       int j, expon;
  17.       char form[10];
  18.       char temp[30];
  19.  
  20.       if (mode == 0) {
  21.         sprintf(form,"%%-.%df",prec);
  22.         sprintf(temp,form,value);
  23.         strcpy(result,temp);
  24.       }
  25.       else {
  26.         sprintf(form,"%%-.%dE",prec);
  27.         sprintf(temp,form,value);
  28.         j = strpos(temp,'E') + 1;
  29.         if (j == 0) fatal("Unrecognized scientific notation");
  30.         sscanf(&temp[j],"%d",&expon);
  31.         sprintf(form,"%-d",expon);
  32.         strcpy(&temp[j-1],"x10\\u");
  33.         strcat(temp,form);
  34.         strcpy(result,temp);
  35.       }
  36. }
  37.  
  38.